﻿<Window x:Class="Led_Application.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Led Application" Height="300" Width="496" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
    
    <Grid>
        
        <Grid.RowDefinitions>
            <RowDefinition Height="29px"> </RowDefinition>
            <RowDefinition Height="150px"></RowDefinition>
            <RowDefinition ></RowDefinition>
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            
            <Rectangle Name="led0" Grid.Column="0" Fill="White"  Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="32768"></Rectangle>
            <Rectangle Name="led1" Grid.Column="1" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="16384"></Rectangle>
            <Rectangle Name="led2" Grid.Column="2" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="8192"></Rectangle>
            <Rectangle Name="led3" Grid.Column="3" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="4096"></Rectangle>
            <Rectangle Name="led4" Grid.Column="4" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="2048"></Rectangle>
            <Rectangle Name="led5" Grid.Column="5" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="1024"></Rectangle>
            <Rectangle Name="led6" Grid.Column="6" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="512"></Rectangle>
            <Rectangle Name="led7" Grid.Column="7" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="256"></Rectangle>
            <Rectangle Name="led8" Grid.Column="8" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="128"></Rectangle>
            <Rectangle Name="led9" Grid.Column="9" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="64"></Rectangle>
            <Rectangle Name="led10" Grid.Column="10" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="32"></Rectangle>
            <Rectangle Name="led11" Grid.Column="11" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="16"></Rectangle>
            <Rectangle Name="led12" Grid.Column="12" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="8"></Rectangle>
            <Rectangle Name="led13" Grid.Column="13" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="4"></Rectangle>
            <Rectangle Name="led14" Grid.Column="14" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="2"></Rectangle>
            <Rectangle Name="led15" Grid.Column="15" Fill="White" Stroke="Gray" StrokeThickness="2" RadiusX="2" RadiusY="2" Margin="5" MouseLeftButtonDown="ledClick" Tag="1"></Rectangle>     
        </Grid>

        <!-- La Magia di WPF consente di trattare una intera griglia come un nuovo componente ... -->
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition ></RowDefinition>
                <RowDefinition ></RowDefinition>
                <RowDefinition ></RowDefinition>
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="110px"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            
            <TextBlock Grid.Row="0" HorizontalAlignment="Left" Name="txtVal" Text="Valore :" VerticalAlignment="Top" FontSize="16" FontFamily="Arial" FontWeight="Bold"/>
            <TextBlock Grid.Row="1" HorizontalAlignment="Left" Name="txtValEx" Text="Valore esadecimale :" VerticalAlignment="Top" FontSize="16" FontFamily="Arial" FontWeight="Bold"/>
            
            <!-- Nuovo attributo: Grid.RowSpan per imporre al controllo ListBox di "occupare" tre righe in altezza. -->
            <ListBox Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" Height="100" HorizontalAlignment="Left" Name="lstComandi" VerticalAlignment="Top" Width="98" />

            <!-- ... griglie dentro griglie... dentro griglie etc... -->
            <!-- Questa ad esempio la usiamo per contenere tutti i bottoni-->
            <Grid Grid.Row="2">
                
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                
                <Button Content="Aggiungi" Grid.Column="0" HorizontalAlignment="Left" Name="btnAdd" VerticalAlignment="Top" Width="75" Click="btnAdd_Click" />
                <Button Content="Salva" Grid.Column="1" HorizontalAlignment="Left" Name="btnSave" VerticalAlignment="Top" Width="75" Click="btnSave_Click" />
                <Button Content="Carica" Grid.Column="2" HorizontalAlignment="Left" Name="btnLoad" VerticalAlignment="Top" Width="75" Click="btnLoad_Click" />
                <Button Content="Salva con nome" Grid.Column="3" HorizontalAlignment="Left" Name="btnSaveAs" VerticalAlignment="Top" Width="90" Click="btnSaveAs_Click"/>
            </Grid>
            
        </Grid>
        
        <Grid Grid.Row="2">
            
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            
            <Button Content="Array" Grid.Column="0" Height="20" Name="btnArray" Click="btnArray_Click" />
        </Grid>
    </Grid>
</Window>
